package com.kxmall.web.controller.coupon;

import com.kxmall.common.core.controller.BaseAppController;
import com.kxmall.common.core.domain.R;
import com.kxmall.coupon.domain.KxStoreCoupon;
import com.kxmall.coupon.domain.KxStoreCouponIssue;
import com.kxmall.coupon.domain.vo.KxStoreCouponIssueVo;
import com.kxmall.coupon.domain.vo.KxStoreCouponUserVo;
import com.kxmall.web.controller.coupon.service.IKxAppCouponService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * app优惠券管理
 *
 * @author kxmall
 * @date 2023-08-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/coupon/app")
public class KxAppCouponController extends BaseAppController {

    private final IKxAppCouponService appCouponService;

    /**
     * 优惠券列表
     * 优惠券状态[1未使用2已使用3已过期]
     */
    @GetMapping("/getUserCoupons")
    public R<List<KxStoreCouponUserVo>> getUserCoupons(Integer status) {
        Long userId = getAppLoginUser().getUserId();
        return R.ok(appCouponService.getUserCoupons(userId,status));
    }


    /**
     * 领取优惠券
     */
    @GetMapping("/obtainCoupon")
    public R<Boolean> obtainCoupon(Long couponId){
        Long userId = getAppLoginUser().getUserId();
        return R.ok("操作成功!", appCouponService.obtainCoupon(couponId, userId));
    }


    /**
     * 获取用户可领取优惠券
     * @return
     */
    @GetMapping("/getObtainableCoupon")
    public R<List<KxStoreCouponIssueVo>> getObtainableCoupon(){
        Long userId = getAppLoginUser().getUserId();
        return R.ok("操作成功!", appCouponService.getObtainableCoupon(userId));
    }


}
